package com.jia;

import java.util.Scanner;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-10 02:22
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//物品个数
        int m = scanner.nextInt();//总体积
        int N = 1010;
        int[] v = new int[N];
        int[] w = new int[N];
        int count = 1;
        while (count++ <= n) {
            v[count] = scanner.nextInt();
            w[count] = scanner.nextInt();
        }
        int[] f = new int[N];
        for (int i = 1; i <= n; i++) {
            for (int j = m; j >= v[i]; j--) {
                f[j] = Math.max(f[j], f[j - v[i]] + w[i]);

            }
        }

        int ans = 0;
        for (int i = 0; i <= m; i++) {
            ans = Math.max(ans, f[i]);
        }
        System.out.println(ans);
    }
}
